package com.movie.repository;

import com.movie.entity.Actor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;

public interface ActorRepository extends JpaRepository<Actor, Long> {
    
    Optional<Actor> findByName(String name);
    
    List<Actor> findByNameContainingIgnoreCase(String name);
    
    @Query("SELECT a FROM Actor a WHERE LOWER(a.name) LIKE LOWER(CONCAT('%', :keyword, '%'))")
    Page<Actor> searchByName(@Param("keyword") String keyword, Pageable pageable);
    
    @Query("SELECT a FROM Actor a WHERE a.id IN :ids")
    List<Actor> findByIdIn(@Param("ids") List<Long> ids);
}